"""
绘制二次函数图像
"""
import matplotlib.pyplot as plt
import numpy as np

# 确定x,y特殊点
x = np.arange(-5,5.1,0.1)
y = x ** 2
# 画图
plt.plot(x,y,label="$y= x^2$",linewidth=2,color="blue",alpha=0.8,linestyle="-")
# 图标题
plt.title("square")
# x,y范围
plt.xlim(-7,7)
plt.ylim(-1,30)
# x,y刻度
plt.xticks(np.arange(-8,9,2))
plt.yticks(range(-2,30,4))
# x,y标题
plt.xlabel("x")
plt.ylabel("y")

# 设置轴位置
# 设置左轴
ax = plt.gca() # 获取坐标轴
axis_l = ax.spines["left"]
axis_l.set_position(("data",0))
# 设置底轴
axis_b = ax.spines["bottom"]
axis_b.set_position(("data",0))
# 设置右轴
axis_r = ax.spines["right"]
axis_r.set_color("None")
# 设置顶轴
axis_t = ax.spines["top"]
axis_t.set_color("None")

# 绘制散点图
x_tck = np.array([-2,1,4])
y_tck = x_tck**2
plt.scatter(x_tck,y_tck,marker="d",s=30,color="red",facecolor="white",edgecolor="black")

# 备注
plt.annotate(
    "this is point",
    xycoords="data",
    xy=(4,16),
    textcoords="offset points",
    xytext=(40,30),
    fontsize=10,
    arrowprops={
        "arrowstyle":"->",
        "connectionstyle":"arc3"

    }
)

plt.legend()
plt.show()

# # 定义二次函数的系数
# a = 1
# b = -2
# c= 3
#
# # 创建一个x值的数组，用于绘图
# x = np.linspace(-10,10,400)
#
# y = a*x**2+b*x+c
#
# # 绘制图像
# plt.plot(x,y,label=f'y={a}x^2+{b}x+{c}')
#
# plt.title('Graph of a Quadratic Function')
# plt.xlabel('x')
# plt.ylabel('y')
#
# # 添加图例
# plt.legend()
#
# # 显示图像
# plt.grid(True) # 显示网格线
# plt.show()
